package com.code.exam.mapper;

import com.code.exam.entity.Admin;
import com.code.exam.entity.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface AdminMapper {

    /**
     * 根据用户名查询用户
     * @param username
     * @return
     */
    @Select("select * from admin where username = #{username}")
    Admin getByUsername(String username);


    /**
     * 管理员注册
     * @param admin
     */
    @Insert("insert into user(id,username,password,email)" + "values (#{id},#{username},#{password},#{email})")
    void register(Admin admin);

    /**
     * 根据id查找管理员
     * @param adminId
     * @return
     */
    @Select("select * from admin where id = #{id}")
    User getById(Long adminId);


    @Update("update admin set password = #{password} where id = #{id}")
    void changepassword(@Param("password") String newPassword, @Param("id") Long adminId);
}
